package com.kucowka.struts.actions.chat.history;

import java.util.TimerTask;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.kucowka.struts.messages.MessageStore;

public class HistorySaverTimerTask extends TimerTask {

	private static final Logger logger = LoggerFactory
			.getLogger(HistorySaverTimerTask.class);

	private HistorySaver hs;

	public void run() {
		if (hs == null) {
			throw new IllegalStateException("HistorySaver was null");
		}

		logger.info("TimerTask: Saving messages");
		if (!hs.saveMessages(MessageStore.getMessages())) {
			logger.info("Message was not saved");
		}
	}

	public void setHistorySaver(HistorySaver hs) {
		this.hs = hs;
	}

}
